package com.fbt.andon.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.andon.service.impl.BoardStationServiceImpl;
;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fbt.andon.domain.BoardStation;

import java.util.Arrays;


@RestController
@RequestMapping("/station")
@Api(description = "岗位信息")
public class BoardStationController extends BaseController {
    @Autowired
    private BoardStationServiceImpl boardStationService;


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/query")
    @ApiOperation("查询所有岗位信息")
    public AjaxResult findCallList() {
        startPage();
        return AjaxResult.success("查询成功", boardStationService.list(null));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/list")
    @ApiOperation("根据工位名称模糊查询产线信息")
    public AjaxResult list(String workName) {
        startPage();
        QueryWrapper<BoardStation> wrapper = new QueryWrapper<>();
        wrapper.like("work_name", workName);
        return AjaxResult.success("查询成功", boardStationService.list(wrapper));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping(value = "/getById/{pkId}")
    @ApiOperation("根据id获取岗位信息详细信息")
    public AjaxResult getInfo(@PathVariable("pkId") Integer pkId) {
        return AjaxResult.success("获取成功", boardStationService.getById(pkId));
    }


    //@PreAuthorize(hasPermi = "mes:andon:add")
    @PostMapping("/add")
    @ApiOperation("新增岗位信息")
    public AjaxResult add(BoardStation boardStation) {
        return AjaxResult.success("新增成功", boardStationService.save(boardStation));
    }


        //@PreAuthorize(hasPermi = "mes:andon:edit")
    @PostMapping("/updateById")
    @ApiOperation("根据id修改岗位信息")
    public AjaxResult edit(@RequestBody BoardStation boardStation) {
        return AjaxResult.success("修改成功", boardStationService.updateById(boardStation));
    }


    //@PreAuthorize(hasPermi = "mes:andon:remove")
    @PostMapping("/batchRemove/{Ids}")
    @ApiOperation("批量删除岗位信息")
    public AjaxResult remove(Long[] ids) {
        return AjaxResult.success("删除成功", boardStationService.removeByIds(Arrays.asList(ids)));
    }


    //@PreAuthorize(hasPermi = "mes:andon:remove")
    @PostMapping("/remove/{id}")
    @ApiOperation("删除岗位信息")
    public AjaxResult removes(Long pkId) {
        return AjaxResult.success("删除成功", boardStationService.removeById(pkId));
    }
}
